<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="股东管理">
<style>
    #back {
        display: block;
        margin-left: 30px;
        padding-top: 10px !important;
    }

    .button-primary {
        margin-left: 15px;
    }
</style>
<form id="searchForm" class="form-panel" action="${basepath}/rest/manage/account/selectMyIncome">
    <a href="${basepath}/rest/manage/account/toPartnerList" id="back">返回上一级</a>
    <ul class="panel-content">
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <select name="transType" placeholder="查询流水类型">
                        <option value="1">提现</option>  <option value="2">下级到店消费</option><option value="3">下级外卖点餐</option> <option value="4">到店消费</option><option value="5">外卖点餐</option></select>
                </div>
            </div>
            <div>
                <label class="time-label control-label">起始日期：</label>

                <div class="time-controls controls">
                    <input name="startDate" class="input-small calendar" type="text" style="width: 80px;"><label>
                    &nbsp;-&nbsp;</label>
                    <input name="endDate" class="input-small calendar" type="text" style="width: 80px;">
                </div>

            </div>
            <div class="form-actions span2">
                <button type="submit" class="button  button-primary">
                    搜索
                </button>
            </div>
            <div class="form-actions span2">
                <a class="button button-danger" href="javascript:delFunction()">批量删除</a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<script>
    var userID = getQueryString('id');
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '5%'},
                {title: '流水日期', dataIndex: 'createTime', elCls: 'center', width: '15%'},
                {
                    title: '流水类型', dataIndex: 'transType', elCls: 'center', width: '20%', renderer: function (value) {
                    switch (value) {
                        case '1':
                            return '账户提现';
                        case '2':
                            return '下级到店消费';
                        case '3':
                            return '下级外卖点餐';
                        case '4':
                            return '到店消费';
                        case '5':
                            return '外卖点餐';
                        case '6':
                            return '余额充值';
                    }
                }
                },
                {
                    title: '流水状态',
                    dataIndex: 'checkStatus',
                    elCls: 'center',
                    width: '20%',
                    renderer: function (value, data) {
                        if (data.transType == 2 || data.transType == 3) {
                            return '<span>已到账</span>';
                        } else if (data.transType == 4 || data.transType == 5) {
                            return '<span>已支付</span>';
                        } else if (data.transType == 1) {
                            switch (value) {
                                case '1':
                                    return '待审核';
                                case '2':
                                    return '已通过';
                                case '3':
                                    return '不通过';
                            }
                        }
                    }
                },
                {title: '流水金额', dataIndex: 'money', elCls: 'center', width: '20%'},
                {
                    title: '操作', dataIndex: 'id', elCls: 'center', width: '15%', renderer: function (value) {
                    return '<a href="javascript:deleteOne(' + value + ')">删除</a>';
                }
                }
            ];

    var store = new Store({
                url: '/rest/manage/account/selectMyIncome',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    userID: userID
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数 据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });

    grid.render();
    //查询框
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*--------------------------------删除用户---------------------------------------------*/
    //删除选中的记录
    function delFunction() {
        BUI.Message.Confirm('确认要删除吗？', function () {
            var selections = grid.getSelection();
            var ids = new Array();
            for (var i = 0; i < selections.length; i++) {
                ids[i] = selections[i].id.toString()
            }
            $.ajax({
                type: "POST",
                url: "/rest/manage/record/deletesJson",
                dataType: "json",
                data: {
                    ids: ids
                },
                success: function (data) {
                    var obj = new Object();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    //删除单个用户
    function deleteOne(value) {
        BUI.Message.Confirm('确认要删除吗？', function () {
            $.ajax({
                type: 'POST',
                url: '/rest/manage/record/deleteJson',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = form.serializeToObject();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    /*--------------------------------删除用户---------------------------------------------*/
</script>

</@page.pageBase>
